package algos;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import javax.imageio.ImageIO;

public class ImageProcessingFilters {

	public static int[][] medianFilter(int[][] image){
    	int K = 12;
    	int yy = 2;
    	int [] kernel = new int[2*K+1];
    	int[][]output = new int[image.length][image[0].length];
    	for (int i = yy; i < image.length-yy; i++) {
			for (int j = yy; j < image[0].length-yy; j++) {
				int k = 0;
				int sum = 0;
				for (int l = -yy; l <= yy; l++) {
					for (int l2 = -yy; l2 <= yy; l2++) {
						kernel[k] = image[i+l][j+l2];
						sum+=image[i+l][j+l2];
						k++;
					}
				}
				
//				Arrays.sort(kernel);
//				output[i][j] = kernel[K];
				sum /=kernel.length;
				output[i][j] = sum;
			}
		}
   	    	
    	return output;
    }
	
}
